//
//  HomeRecommendHeaderView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/20.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "CustomProjectHeaderView.h"

#import <OCSkeleton.h>

@interface CustomProjectHeaderView () <OCGradientsOwner>

/**
 *displayButton
 */
@property (nonatomic, strong) QMUIButton *displayButton;


/**
 *imageContainerView
 */
@property (nonatomic, strong) OCGradientContainerView *imageContainerView;
/**
 *titleContainerView
 */
@property (nonatomic, strong) OCGradientContainerView *titleContainerView;

@end

@implementation CustomProjectHeaderView


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self setupSubviews];
        [self setContainerViews];
    }
    return self;
}
- (void)setupSubviews {//
    self.displayButton = [QMUIButton new];
    [self.displayButton setImage:LOAD_IMAGE(@"home_header_recommend") forState:UIControlStateNormal];
    self.displayButton.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
    self.displayButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.displayButton setTitleColor:[UIColor qmui_colorWithHexString:@"#333333"] forState:UIControlStateNormal];
    self.displayButton.spacingBetweenImageAndTitle = 5.0;
    [self.contentView addSubview:self.displayButton];
    [self.displayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(20.0);
        make.bottom.mas_equalTo(self.contentView).offset(-7.0);
        make.right.mas_equalTo(self.contentView).offset(-20.0);
    }];
    self.displayButton.userInteractionEnabled = false;
}
- (void)setContainerViews {
    self.imageContainerView = [OCGradientContainerView new];
    [self.contentView addSubview:self.imageContainerView];
    [self.imageContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.displayButton.imageView);
    }];
    //
    self.titleContainerView = [OCGradientContainerView new];
    [self.contentView addSubview:self.titleContainerView];
    [self.titleContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageContainerView.mas_right).offset(self.displayButton.spacingBetweenImageAndTitle);
        make.centerY.mas_equalTo(self.imageContainerView);
        make.right.mas_equalTo(self.contentView).offset(-20.0);
        make.height.mas_equalTo(self.displayButton.titleLabel.font.lineHeight);
    }];
}


- (void)setTitle:(NSString *)title {
    _title = title;
     [self.displayButton setTitle:title forState:UIControlStateNormal];
}
- (void)setImageName:(NSString *)imageName {
    _imageName = imageName;
    [self.displayButton setImage:LOAD_IMAGE(imageName) forState:UIControlStateNormal];
}

- (void)setIsLoadedData:(BOOL)isLoadedData {
    _isLoadedData = isLoadedData;
    //
    for (UIView *view in [self skeletonViews]) {
        view.backgroundColor = isLoadedData?[UIColor clearColor]:[OCGradientContainerView appearance].backgroundColor;
        view.alpha = isLoadedData?0:1;
    }
}


#pragma mark - OCGradientsOwner
- (NSArray <OCGradientLayer *>*)gradientLayers {
    if (self.imageContainerView && self.titleContainerView) {
        return @[self.imageContainerView.gradientLayer, self.titleContainerView.gradientLayer];
    }
    return nil;
}

- (NSArray <UIView *>*)skeletonViews {
    if (self.imageContainerView && self.titleContainerView) {
        return @[self.imageContainerView, self.titleContainerView];
    }
    return nil;
}




+ (CGFloat)defaultHeight {
    return 44.0f;
}


@end
